/**
 * 创建 Virtual DOM
 * @param {string} type 类型
 * @param {object | null} props 属性
 * @param  {createElement[]} children 子元素
 * @return {object} Virtual DOM
 */
export default function createElement(type, props, ...children) {
  const childElements = [...children].reduce((res, child) => {
    if (child === false || child === true || child === null) {
      return res
    }

    if (child instanceof Object) {
      res.push(child)
    } else {
      res.push(createElement('text', { textContent: child }))
    }

    return res
  }, [])

  return {
    type,
    props: Object.assign({ children: childElements }, props),
    children: childElements
  }
}
